package com.tuniu.agents.config;

import com.tuniu.agents.advisor.ChatEnvironmentMemory;
import com.tuniu.agents.common.IdGenerator;
import com.tuniu.agents.common.filter.ConversationFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Filter manager
 */
@Configuration
public class FilterConfig {

    @Bean
    public FilterRegistrationBean<ConversationFilter> conversationFilter(ChatEnvironmentMemory chatEnvironmentMemory, IdGenerator idGenerator) {
        FilterRegistrationBean<ConversationFilter> registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(new ConversationFilter(idGenerator, chatEnvironmentMemory));
        registrationBean.addUrlPatterns("/api/chat/*", "/api/assistant/*"); // Apply filter only to /api/* paths
        registrationBean.setOrder(1); // Set filter order
        return registrationBean;
    }

}
